﻿package plugin.chatflash.handler
{
    import __AS3__.vec.*;
    import cmd.*;
    import com.core.*;
    import com.sh.game.global.*;
    import flash.geom.*;
    import flash.utils.*;
    import manager.*;
    import pluginfw.nio.*;
    import pluginfw.nio.imsg.*;
    import view.message.*;

    public class ChatFlashHandler extends Object implements IGroupHandler
    {
        private var _delayMsgVec:Vector.<Object>;
        private var _delayUnionMsgVec:Vector.<Object>;

        public function ChatFlashHandler()
        {
            this._delayMsgVec = new Vector.<Object>;
            this._delayUnionMsgVec = new Vector.<Object>;
            return;
        }// end function

        public function dealSimpleMessage(param1:ISimpleMessage) : void
        {
            var _loc_3:Object = null;
            var _loc_4:String = null;
            var _loc_5:Array = null;
            var _loc_6:Boolean = false;
            var _loc_7:Boolean = false;
            var _loc_8:Boolean = false;
            var _loc_9:Boolean = false;
            var _loc_10:Boolean = false;
            var _loc_11:Boolean = false;
            var _loc_2:* = param1.getCmd();
            switch(param1.getCmd())
            {
                case ChatCMD.ChannelWorld:
                case ChatCMD.ChannelTeam:
                case ChatCMD.ChannelShop:
                case ChatCMD.ChannelUnion:
                case ChatCMD.ChannelSystem:
                case ChatCMD.ChannelPrivate:
                {
                    _loc_3 = param1.getParam();
                    if (_loc_3 is Array)
                    {
                        _loc_3 = _loc_3[1];
                    }
                    ModelProxy.change("chat", "normalmsg", {cmd:_loc_2, msg:_loc_3});
                    if (_loc_2 == ChatCMD.ChannelPrivate)
                    {
                        _loc_6 = ModelProxy.getValue("data", "simpleChatIsInit");
                        if (!_loc_6)
                        {
                            this._delayMsgVec.push({cmd:_loc_2, msg:_loc_3});
                            ModelProxy.change("data", "simpleChatMsg", this._delayMsgVec);
                            ModelProxy.change("mainui", "addSimpleChator", _loc_3);
                        }
                        else
                        {
                            _loc_7 = ModelProxy.getValue("data", "isSimpleChatOpen");
                            if (!_loc_7)
                            {
                                _loc_8 = ModelProxy.getValue("data", "isPrivateLight");
                                if (!_loc_8)
                                {
                                    ModelProxy.change("mainui", "addSimpleChator", _loc_3);
                                }
                            }
                        }
                    }
                    else if (_loc_2 == ChatCMD.ChannelUnion)
                    {
                        _loc_9 = ModelProxy.getValue("data", "unionChatIsInit");
                        if (!_loc_9)
                        {
                            this._delayUnionMsgVec.push({cmd:_loc_2, msg:_loc_3});
                            if (this._delayUnionMsgVec.length > 30)
                            {
                                this._delayUnionMsgVec.shift();
                            }
                            ModelProxy.change("data", "unionChatMsg", this._delayUnionMsgVec);
                            ModelProxy.change("mainui", "addUnionChator", _loc_3);
                        }
                        else
                        {
                            _loc_10 = ModelProxy.getValue("data", "isUnionChatOpen");
                            if (!_loc_10)
                            {
                                _loc_11 = ModelProxy.getValue("data", "isUnionLight");
                                if (!_loc_11)
                                {
                                    ModelProxy.change("mainui", "addUnionChator", _loc_3);
                                }
                            }
                        }
                    }
                    break;
                }
                case ChatCMD.ChannelStage:
                {
                    _loc_4 = param1.getParam();
                    _loc_5 = _loc_4.split("#%", 2);
                    ModelProxy.change("chat", "normalmsg", {cmd:_loc_2, msg:_loc_5[1], serverid:_loc_5[0]});
                    break;
                }
                case ChatCMD.ChannelSpecial:
                {
                    ModelProxy.change("chat", "normalmsg", {cmd:_loc_2, msg:param1.getParam()});
                    break;
                }
                case ChatCMD.PosAnnounce:
                {
                    ModelProxy.change("chat", "posAnnounce", param1.getParam());
                    break;
                }
                case ChatCMD.WdAnnounce:
                {
                    ModelProxy.change("chat", "WdAnnounce", param1.getParam());
                    break;
                }
                case ChatCMD.BigAnnounce:
                {
                    ModelProxy.change("mainui", "bigfont", param1.getParam());
                    break;
                }
                case ChatCMD.GMAnnounce:
                {
                    ModelProxy.change("mainui", "showHorn", {isGm:"gm", titleMsg:"", RoleName:"", tempContent:param1.getParam(), TalkContent:param1.getParam()});
                    break;
                }
                case 9:
                {
                    ModelProxy.change("tips", "arm", {data:param1.getParam(), p:new Point(GlobalLayer.instance.root.mouseX, GlobalLayer.instance.root.mouseY)});
                    break;
                }
                case ChatCMD.SystemAlert:
                {
                    Alert2.show(param1.getParam(), "", ["确认"], null, null);
                    break;
                }
                case ChatCMD.Annouce:
                {
                    ModelProxy.change("mainui", "annouce", param1.getParam());
                    break;
                }
                case ChatCMD.Annouce2:
                {
                    ModelProxy.change("mainui", "annouce1", param1.getParam());
                    break;
                }
                case ChatCMD.Annouce3:
                {
                    ModelProxy.change("mainui", "annouce2", param1.getParam());
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

        public function dealBufferMessage(param1:IBufferMessage) : void
        {
            var _loc_3:Input = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_2:* = new Object();
            _loc_3 = new Input(null);
            var _loc_4:* = param1.getBody();
            param1.getBody().position = 0;
            _loc_3.setBytes(_loc_4);
            switch(param1.getCmd())
            {
                case ChatCMD.ANNOUNCEMSG:
                {
                    _loc_2.annouceType = _loc_3.readByte();
                    _loc_2.configId = _loc_3.readVarInt(false);
                    _loc_2.content = _loc_3.readString();
                    _loc_5 = _loc_3.readShort();
                    _loc_2.params = new Array();
                    _loc_6 = 0;
                    while (_loc_6 < _loc_5)
                    {
                        
                        _loc_2.params[_loc_6] = _loc_3.readString();
                        _loc_6++;
                    }
                    switch(int(_loc_2.annouceType))
                    {
                        case 8:
                        {
                            WarningManager.show(_loc_2.configId, _loc_2.params);
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    break;
                }
                case ChatCMD:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealProxyMessage(param1:IProxyMessage) : void
        {
            return;
        }// end function

    }
}
